<template>
  <div>
    <el-card class="search-card">
      <BasicForm
        ref="formData"
        :formColumns="formItems"
        :dataSource="formData"
        :handleSearchForm="handleQueryForm"
        @getFormData="getFormData"
      />
    </el-card>
    <el-card class="table-card">
      <SkusTable
        ref="skusTable"
        showActionCol
        showPagination
        :tableHeight="480"
        :defaultMinWidth="100"
        :dataSource="TableInfo.list"
        :columns="TableInfo.columns"
        :loading="TableInfo.loading"
        :pageSizes="pageSizes"
        :pagination="pagination"
        :total="pagination.total"
        :actionRender="renderTableBtnAction"
        @pageChange="handlePageChange"
        @pageSizeSelect="handlePageSizeChange"
      />
    </el-card>
  </div>
</template>
<script>
import BasicForm from '@/components/BasicForm';
import SkusTable from '@/components/skusTable';
import skusPage from '@/mixins/commodity/skusPage';
import { getTableAction } from '@/utils/getBtnsRender';
import { getInitFormData, TableInfo, getSearchParamBySearchType } from '@/utils/getUtils';
import { setAuthBtnId } from '@/utils/bizUtils';
import { FORM_ITEMS, TABLE_COLUMNS } from './constants/list';
import { getPagerService } from '@/api/basics/categoryManage/categoryToAudit';
import { queryOAUrlService } from '@/api/public';
export default {
  mixins: [skusPage],
  components: {
    BasicForm,
    SkusTable,
  },
  data () {
    return {
      formItems: FORM_ITEMS,
      formData: getInitFormData(FORM_ITEMS),
      TableInfo: new TableInfo({ columns: TABLE_COLUMNS }),
      btnLoading: {
        export: false,
        exportTemp: false
      },
    }
  },
  created () {
    this.getTableData()
  },
  methods: {
    // 渲染表格操作栏按钮
    renderTableBtnAction (h, { row }) {
      const actionList = [
        { label: '查看', method: this.handleView },
        {
          label: '审核',
          method: this.handleAudit,
          hasAuth: true,
        }
      ]
      return getTableAction({ h, row, actionList, showBtn: this.showBtn });
    },
    getSearchParam () {
      const formItems = [
        ...FORM_ITEMS,
        { prop: 'reviewState', searchType: 'EQ' }
      ]
      const formData = { ...this.formData, reviewState: '1' }
      const searchParam = getSearchParamBySearchType(formItems, formData)
      return JSON.stringify(searchParam)
    },
    // 获取表格数据
    async getTableData () {
      setAuthBtnId('查询')
      const data = { searchParam: this.getSearchParam(), ...this.paginationParams }
      const res = await getPagerService(data, this.TableInfo.setLoading)
      if (res?.retData) {
        this.TableInfo.setList(res.retData.results)
        this.setTotalNum(res.retData.totalNum)
      }
    },
    // 审核
    async handleAudit (row) {
      setAuthBtnId('审核')
      const data = { oaRequestId: row.workflowRequestId }
      const res = await queryOAUrlService(data, this.TableInfo.setLoading)
      if (res?.retData) window.open(res.retData)
    },
    // 查看
    handleView (row) {
      const { href } = this.$router.resolve({
        name: 'categoryAuditView',
        query: { uuid: row.uuid }
      })
      window.open(href, '_blank')
    },
  }
}
</script>
